package com.wqz.dao;

import com.wqz.pojo.Provider;
import com.wqz.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.*;

public class ProviderDaoTest {

    @Test
    public void modifyProvider() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        ProviderDao providerDao = sqlSession.getMapper(ProviderDao.class);
        Provider provider = new Provider();
        provider.setId(16);
        provider.setProCode("33333");
        provider.setProName("33333");
        provider.setProDesc("33333");

        try {
            int res = providerDao.modifyProvider(provider);
            System.out.println("受影响的行数：" + res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void addProvider() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        ProviderDao providerDao = sqlSession.getMapper(ProviderDao.class);
        Provider provider = new Provider();
        provider.setProCode("11111");
        provider.setProName("11111");
        provider.setProDesc("11111");

        try {
            int res = providerDao.addProvider(provider);
            System.out.println("受影响的行数：" + res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void findProvider() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        ProviderDao providerDao = sqlSession.getMapper(ProviderDao.class);
        Provider provider = new Provider();
        provider.setProCode(null);
        provider.setProName("33");
        provider.setProDesc("3");

        try {
            List<Provider> providerList = providerDao.findProvider(provider);
            for(Provider provider1 : providerList) {
                System.out.println(provider1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}